#ifndef SEARCHWIKI_H
#define SEARCHWIKI_H

#include <wiki/wiki.h>

#include <functional>

typedef std::function<QString(QString input)> OnSearchCallback;

static OnSearchCallback scbk_default = [](QString input) {
    return input;
};

class SearchWiki : public Wiki
{
public:
    SearchWiki();

public:
    WIKI_AUTOLOAD
    WIKI_USE_URL
    WIKI_FORWARED_CONTENT

    void setScbk(const OnSearchCallback &newScbk)
    {
        m_scbk = newScbk;
    }

protected:
    OnSearchCallback m_scbk = scbk_default;
};

#define SEARCHWIKI(x,y,z,o) \
    class x : public SearchWiki { \
    public: \
        QString name() override { return y; } \
        QString prefix() override { return z; } \
        QString content(const QString &text) override { return text.isEmpty()?QString(o).isEmpty()?prefix() + text:o:prefix()+text; } \
    };
#define SEARCHWIKI_INIT(x,y,z) \
    class x : public SearchWiki { \
    public: \
        x(); \
        QString name() override { return y; } \
        QString prefix() override { return z; } \
        QString content(const QString &text) override { return text.isEmpty()?prefix():m_scbk(text); } \
    };

SEARCHWIKI(StackRoom, "Stack Room", "https://stackoom.com/search?l=cn_en&q=", "")
SEARCHWIKI(StackExchange, "Stack Exchange", "https://stackexchange.com/search?q=", "")
SEARCHWIKI(ZhiHu, "知乎 - 搜索", "https://www.zhihu.com/search?type=content&q=", "")
SEARCHWIKI(PostsTelecom, "人民邮电出版社", "https://www.ptpress.com.cn/search/books?keyword=", "")

// 特殊：
SEARCHWIKI(MavenSearch, "Maven - 搜索", "https://mvn.coderead.cn/", "")

SEARCHWIKI(RustDoc, "Rust - Docs.rs", "https://docs.rs/releases/search?query=", "https://docs.rs")

// 初始化处理：
SEARCHWIKI_INIT(ItHome, "IT之家 - 搜索", "https://www.ithome.com/")

SEARCHWIKI(Taobao, "淘宝网 - 搜索", "https://s.taobao.com/search?q=", "https://s.taobao.com/search")

#endif // SEARCHWIKI_H
